﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NHibernate;
using NHibernate.Criterion;

using Revis.VClinicNet.Core.Domain.Repository;

namespace Revis.VClinicNet.Core.Domain.Persistence.Nh
{
    public class PatientRepository : RepositoryBase<Patient>, IPatientRepository
    {
        public PatientRepository(ISessionFactory factor) :
            base(factor)
        {
        }

        public Patient Find(string pesel)
        {
            return Session.CreateCriteria<Patient>("p")
                .Add(Expression.Eq("p.Personal.Pesel", pesel)).UniqueResult<Patient>();
        }

        public IList<Visit> Visits(long patientId)
        {
            IList<Visit> visits = Session.CreateCriteria<Visit>("v")
                .Add(Expression.Eq("v.Patient.Id", patientId))
                .List<Visit>();
            return visits;
        }
    }
}
